<?php
namespace Home\Controller;
use Think\Controller;
class StudentController extends BackController {
    protected $limitnum = 10;
	public function index(){
	    $ppid = I('ppid');
		$user = M('user')->select();
        $where="";
		$this->assign('sc_user',$user);

        $result['title'] = I('title');
        if ($result['title']){
            $where['student_id|name'] = array('like','%'.$result['title'].'%');
        }
        //课程
        $result['kname'] = I('kname');
        if ($result['kname']){
            $where['curriculum_id'] = array('eq',$result['kname']);
        }
        //电话
        $result['tel'] = I('tel');
        if ($result['tel']){
            $where['phone'] = array('eq',$result['tel']);
        }
		$sc_student = M('sc_student');
		$pageid = I('get.pageid',1,'int');//接收当前页\
		if(session('qe_user')['xid']!=0){
			$where['xid'] = array('eq',session('qe_user')['xid']);
		}
        if ($ppid ==2){
            $where['class_id'] = array('eq',0);
        }else{
            $where['class_id'] = array('neq',0);
        }
        //分页
        $result['limit'] = I('p');
        if ($result['limit'] <= 0 || empty($result['limit'])){
            $limit['limit'] = 1;
        }else{
            $limit['limit'] = $result['limit'];
        }
        $end = $limit['limit']*$this->limitnum;
        $star = ($limit['limit']-1)*$this->limitnum;

		$count = $sc_student->where($where)->count();//计算出总的记录数
        $Page = new \Think\Page($count, $this->limitnum);// 实例化分页类 传入总记录数和每页显示的记录数
        $Page->setConfig('theme', " <ul class='pagination pagination-large'></li><li>%FIRST%</li><li>%UP_PAGE%</li><li>%LINK_PAGE%</li><li>%DOWN_PAGE%</li><li>%END%</li><li><a> %HEADER%  %NOW_PAGE%/%TOTAL_PAGE% 页</a></ul>");//(对thinkphp自带分页的格式进行自定义)
        $show = $Page->show(); // 分页显示输出
		$sc_data = $sc_student->where($where)->order('id desc')->limit($star,$end)->select();
		$kwhere['xid'] = array('eq',session('qe_user')['xid']);
		$kname = M('curriculum')->where($kwhere)->getField('id,cname');
		foreach($sc_data as $k=>$v){
			$sc_data[$k]['record_data'] = $this->record_data($v['id']);
			$sc_data[$k]['xs_name'] = $this->username($v['xsid']);
			$sc_data[$k]['am_name'] = $this->basname($v['am_id']);
			$sc_data[$k]['state_name'] = $this->basname($v['state_id']);
			$sc_data[$k]['x_name'] = $this->basname($v['xid']);
			$sc_data[$k]['k_name'] = $kname[$v['curriculum_id']];
		}
		$this->assign('sc_data',$sc_data);
		$this->assign('page',$show);
		
		$campus = M('other')->select();
		$this->assign('campus',$campus);
		$this->assign('kname',$kname);
		$this->assign('map',$result);
		//相关课程
		//var_dump($sc_data);
		$this->display();
	}
	public function edit(){
		if(IS_POST) {
			$student = D('Student');
			$id = I('post.id','','int');
			$_POST['up'] = 1;
			$_POST['edit_time'] = date("Y-m-d");
				if($student->create()) {
						if($student->where('id='.$id)->save($_POST) !== false) {
								$this->success('报名成功',U('Studentlist/index'));
						}else {
								$this->error('报名失败',U('Studentlist/index?'));
						}
				}else {
						$this->error($record->getError());
				}
		}
	}

	public function MoveRecord(){
		$this->display();
	}
	public function Strange(){
		$this->display();
	}
	public function BirthdayStudents(){
		$this->display();
	}
}